package com.neuedu.hisboot.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.neuedu.hisboot.entity.Customer;
import com.neuedu.hisboot.mapper.CustomerMapper;
import com.neuedu.hisboot.service.ICustomerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  病人信息管理服务实现类
 * </p>
 *
 * @author jaun
 * @since 2025-07-04
 */
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements ICustomerService {


    @Override
    public List<Customer> getCustomerByNameOrNumber(String name, String number) {
        QueryWrapper<Customer> queryWrapper = new QueryWrapper<>();
        // 构造查询条件
        if(StringUtils.hasText(name)){
            queryWrapper.like("realName", name);
        }
        if(StringUtils.hasText(number)){
            queryWrapper.like("idnumber", number);
        }

        queryWrapper.eq("delMark", 1);
        return this.list(queryWrapper);
    }

    @Override
    public List<Customer> getByGender(Integer gender) {
        QueryWrapper<Customer> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("gender", gender);
        queryWrapper.eq("delMark", 1);
        return this.list(queryWrapper);
    }

    @Override
    public List<Customer> getByChannel(Integer channel) {
        QueryWrapper<Customer> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("channel", channel);
        queryWrapper.eq("delMark", 1);
        return this.list(queryWrapper);
    }

    @Override
    public Customer getByIdNumber(String idNumber) {
        QueryWrapper<Customer> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("idnumber", idNumber);
        queryWrapper.eq("delMark", 1);
        return this.getOne(queryWrapper);
    }

    @Override
    public Customer getByPhone(String phone) {
        QueryWrapper<Customer> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("phone", phone);
        queryWrapper.eq("delMark", 1);
        return this.getOne(queryWrapper);
    }
}
